//
//  StatusListModel.m
//  1-MushroomStreet-自定义tabbar
//
//  Created by xmg on 16/1/27.
//  Copyright © 2016年 grx. All rights reserved.
//

#import "StatusListModel.h"

#import <MJExtension/MJExtension.h>

@implementation StatusListModel



+ (NSString *)mj_replacedKeyFromPropertyName121:(NSString *)propertyName
{
    // nickName -> nick_name
    return [propertyName mj_underlineFromCamel];
}


//设置微博发布时间
- (NSString *)created_at
{
    // 帖子的审核通过时间
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy";
    NSDate *createdAtDate = [fmt dateFromString:_created_at];
    
    if (createdAtDate.bs_isThisYear) { // 今年
        if (createdAtDate.bs_isYesterday) { // 昨天
            fmt.dateFormat = @"昨天 HH:mm:ss";
            return [fmt stringFromDate:createdAtDate];
        } else if (createdAtDate.bs_isToday) { // 今天
            NSCalendar *calendar = [NSCalendar bs_calendar];
            NSCalendarUnit unit = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
            NSDateComponents *cmps = [calendar components:unit fromDate:createdAtDate toDate:[NSDate date] options:0];
            
            if (cmps.hour >= 1) { // 时间间隔 >= 1小时
                return [NSString stringWithFormat:@"%zd小时前", cmps.hour];
            } else if (cmps.minute >= 1) { // 1小时 > 时间间隔 >= 1分钟
                return [NSString stringWithFormat:@"%zd分钟前", cmps.minute];
            } else { // 时间间隔 < 1分钟
                return @"刚刚";
            }
        } else {
            fmt.dateFormat = @"MM-dd HH:mm:ss";
            return [fmt stringFromDate:createdAtDate];
        }
    } else { // 不是今年
        return _created_at;
    }
}

//截取微博发布用户的信息
- (void)setUser:(UserModel *)user{
    _user = user;
    
    [UserModel mj_objectArrayWithKeyValuesArray:user];
    
}


//每隔cell的高度
- (CGFloat)cellHeight{
    if (_cellHeight) return _cellHeight;
    
    //头像
    _cellHeight = 10 + 50 + 10;
    
    //文字
    CGFloat textMaxW = kScreenW - 2 * 10;
    _cellHeight += [self.text boundingRectWithSize:CGSizeMake(textMaxW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15]} context:nil].size.height + 10;
    
    //底部工具条
    _cellHeight += 10 + 44;
    
    return _cellHeight;
}



@end
